package com.onlineMIS.ORM.entity.headQ.finance;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;

import com.onlineMIS.common.Common_util;
import com.onlineMIS.common.ExcelTemplate;

/**
 * @Destrice: 总部费用类型明细表
 * @author Administrator
 *
 */
public class ExpenseHqItemDetailsTemplate extends ExcelTemplate {


	private List<ExpenseHqItem> list = new ArrayList<ExpenseHqItem>();

	public ExpenseHqItemDetailsTemplate(String templateWorkbookPath,List<ExpenseHqItem> list) throws IOException {
		super(templateWorkbookPath);
		this.list = list;
	}

	public HSSFWorkbook process() {
		HSSFSheet sheet = templateWorkbook.getSheetAt(0);

		for (int i = 0; i < list.size(); i++) {
			ExpenseHqItem item = list.get(i);
			Row row = sheet.createRow(i+1);

			row.createCell(0).setCellValue(item.getExpenseHq().getId());
			row.createCell(1).setCellValue(item.getExpenseHq().getFinanceCategory().getItemName()); 
			row.createCell(2).setCellValue(item.getExpenseHq().getTypeHQMap().get(item.getExpenseHq().getType()));
			row.createCell(3).setCellValue(item.getExpenseHqType().getName()); 
			row.createCell(4).setCellValue(Common_util.dateFormat_f.format(item.getExpenseHq().getExpenseDate())); 
			row.createCell(5).setCellValue(Double.toString(item.getAmount()));
			String amouont = Double.toString(item.getAmount());
			if (item.getExpenseHq().getType() == ExpenseHq.DOCUMENT_TYPE_HQ_COST) {//费用单
				row.createCell(7).setCellValue(amouont);
			}else if (item.getExpenseHq().getType() == ExpenseHq.DOCUMENT_TYPE_HQ_INCOME) {//收益单
				row.createCell(6).setCellValue(amouont);
			}

		}
		return templateWorkbook;
	}

}
